<?php
include '../../util/TransactionBD.php';
include '../../model/entidades/Alternativa.php';
 
class AlternativaGateway{
  
    public function inserirAlternativa(Alternativa &$alternativa, $id_pergunta){
        $sql = "INSERT INTO alternativa VALUES(NULL,'{$alternativa->getDescricao()}','{$alternativa->getExplicacao()}',$id_pergunta);";
        TransactionBD::abre();
        $con = TransactionBD::getConexao();
        $con->exec($sql);
        $id = $con->lastInsertId();
        $alternativa->setId($id);
        TransactionBD::fechar();
     }
     
    public function alterarAlternativa(Alternativa $alternativa){
        $sql = "UPDATE alternativa SET descricao = '{$alternativa->getDescricao()}', explicacao = '{$alternativa->getExplicacao()}', id_pergunta = '{$alternativa->getIdPergunta()}' WHERE alternativa.id = '{$alternativa->getId()}'";
        TransactionBD::abre();
        $con = TransactionBD::getConexao();
        $con->exec($sql);
        TransactionBD::fechar();
    }
    
    public function excluirAlternativa($id){
        $sql = "DELETE FROM alternativa WHERE id='$id';";
        TransactionBD::abre();
        $con = TransactionBD::getConexao();
        $con->exec($sql);
        TransactionBD::fechar();
    }
}
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

